<template>
  <PageWrapper dense contentFullHeight fixedHeight contentClass="flex">
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="handleCreate">新增</a-button>
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '编辑',
              onClick: handleEdit.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
    <Modal @register="registerModal" @success="handleSuccess" :width="900" />
  </PageWrapper>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicTable, useTable, TableAction, BasicColumn } from '/@/components/Table';
  import { PageWrapper } from '/@/components/Page';
  import { useModal } from '/@/components/Modal';
  import Modal from './modal.vue';
  import { userAgreementData } from './userAgreement.data';
  const columns: BasicColumn[] = [
    {
      title: '名称',
      dataIndex: 'name',
    },
  ];

  export default defineComponent({
    name: 'UserAgreement',
    components: { BasicTable, PageWrapper, Modal, TableAction },
    setup() {
      const [registerModal, { openModal }] = useModal();
      const [registerTable, { reload }] = useTable({
        // api: listApi,
        dataSource: userAgreementData,
        columns,
        useSearchForm: false,
        bordered: true,
        actionColumn: {
          width: 150,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
        },
      });

      function handleEdit(record: Recordable) {
        openModal(true, {
          record,
          isUpdate: true,
        });
      }

      function handleSuccess() {
        reload();
      }

      return {
        registerTable,
        registerModal,
        handleEdit,
        handleSuccess,
      };
    },
  });
</script>
<style scoped lang="less">
.preview-img {
  width: 150px;
  display: flex;
  justify-content: center;
}
</style>
